/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author israel
 */
@Entity
public class Neighborhood extends AbstractEntity{
    private static final long serialVersionUID = 1L;
    
    @Column(length=60)
    private String name;

    @ManyToOne
    @JoinColumn(name="city_id")
    private City city;

    public Neighborhood() {
    }

    @Override
    public void generateHash(){
        if(getId() == null){
            String hash = this.getName()
                    + ((this.getCity() != null) ? this.getCity().getId() : null);
            this.setId(Long.valueOf(EncryptionUtil.encrypt(hash).hashCode()));
        }
    }

    public Neighborhood(String name, City city) {
        this.name = name;
        this.city = city;
    }

    public City getCity() {
        return city;
    }

    public void setCity(City city) {
        this.city = city;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
